package com.dc.adaptor.convertor;

import java.util.ArrayList;
import java.util.List;

import org.pentaho.di.core.RowMetaAndData;
import org.pentaho.di.core.row.ValueMeta;
import org.pentaho.di.core.row.ValueMetaInterface;

import com.dc.adaptor.persistance.bean.SipRecvPack;
/**
 * 
 * @author lisx 2012-08-25
 *
 */
public class CarsMessageConvertor4Input extends BaseMessageConvertor {
	@Override
	public List<RowMetaAndData> packToMetaData(SipRecvPack sipReceivePack){
		String content = sipReceivePack.getSipContent().getContent();
		String[] str = content.split("\r\n");
		if(logger.isInfoEnabled()){
			logger.info("CarsMessageConvertor4Input split row,length is "+str.length);
		}
		String[] title = str[0].split(":;");
		if(logger.isInfoEnabled()){
			logger.info("CarsMessageConvertor4Input split title,length is "+title.length);
		}
		List<RowMetaAndData> list = new ArrayList<RowMetaAndData>();
		for(int i=1,j=str.length; i<j; i++){			
			RowMetaAndData mData = new RowMetaAndData();
			String[] row = str[i].split(":;",50);
			for(int k=0,h=title.length; k<h; k++) {
				mData.addValue(new ValueMeta(title[k], ValueMetaInterface.TYPE_STRING), row[k]);
			}			
			if(i+1==j){
				mData.addValue(new ValueMeta("SIP_PACKFINISH", ValueMetaInterface.TYPE_STRING), "OK");
			}else{
				mData.addValue(new ValueMeta("SIP_PACKFINISH", ValueMetaInterface.TYPE_STRING), "Fail");
			}
			list.add(mData);
		}
		return list;
	}
}
